package com.itheima.utils;

/**
 * @author jshstart
 * @creat 2020-11-17 10:10
 */
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 短信发送工具类
 */
public class SMSUtils {
    public static final String VALIDATE_CODE = "SMS_205458553";//发送短信验证码
    public static final String ORDER_NOTICE = "SMS_205468484";//体检预约成功通知
    /**
     *  注册会员发送短信
     */
    public static String registerSendCode(String sendyourTelephoneNumber,String codeNumber)  {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4G2HvREz6mwjydJgQ2SP", "ULj2HShSaScZHhv79znIWQzZ3Trxhd");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", sendyourTelephoneNumber);
        request.putQueryParameter("SignName", "打篮球");
        request.putQueryParameter("TemplateCode", VALIDATE_CODE);
        request.putQueryParameter("TemplateParam", "{\"code\":\""+codeNumber+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
return codeNumber;
    }

    /**
     * 预约成功 发送短信通知
     */

    public static void appointment_Is_Ok(String sendyourTelephoneNumber,String codeNumber)  {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4G2HvREz6mwjydJgQ2SP", "ULj2HShSaScZHhv79znIWQzZ3Trxhd");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", sendyourTelephoneNumber);
        request.putQueryParameter("SignName", "打篮球");
        request.putQueryParameter("TemplateCode", ORDER_NOTICE);
        request.putQueryParameter("TemplateParam", "{\"code\":\""+codeNumber+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {

//        SMSUtils.registerSendCode("15515693262", "999999");
            SMSUtils.appointment_Is_Ok("18790889102","11111");
            //https://gitee.com/jsh1225/hm-health-group-1
            //https://gitee.com/jsh1225/hm-health-group-1.git
    }

}